#!/usr/bin/python
from pylab import *

# import numpy as np
# import matplotlib.pyplot as plt
# import matplotlib
from matplotlib.collections import PatchCollection
# import matplotlib.path as mpath
import matplotlib.patches as mpatches
import matplotlib.lines as mlines




# font = "sans-serif"
# fig = figure(figsize=(5,5))
# ax = fig.add_axes([0,0,1,1])  # the ticks not displayed
# ax = fig.add_axes([0.1,0.1,0.8,0.8])
# ax = fig.add_subplot(111)


# create a figure with a set of subplots already made
fig, ax = plt.subplots()
# fig, (ax1, ax2) = plt.subplots(1,2, sharey=True)


# ax.add_artist/collection/line/patch/table


# add text
# t = text(0.5, 0.4, "some text", ha="left", va="bottom", color="red")
t = text(0.5, 0.4, "some text", bbox=dict(facecolor="red", alpha=0.5), color="yellow")
ax.add_artist(t)
# ax.text(0.5, 0.5-0.15, "Circle", ha="center", family=font, size=14) //is valid ???

# add lines
# line = mlines.Line2D([0,0.2],[0.3,0.4], lw=4, color='r', alpha=0.4) # draw a line (0,0.3) - (0.2,0.4)
lineX = linspace(0,2,5)
lineY = [0,0,1,0,0]
line = mlines.Line2D(lineX, lineY, lw=4, c='b', alpha=0.4)
# setp(line, color='g')           # set the properties of 'line'

ax.add_line(line)
ax.add_line(mlines.Line2D([0,0.2],[0.3,0.4], lw=4, color='r', alpha=0.4))


# add patch
patch1 = mpatches.Circle((0.5,0.5), 0.1,ec="none")
patch2 = mpatches.Rectangle((0.1,0.1), 0.2, 0.2, ec='none')
ax.add_patch(patch1)
ax.add_patch(patch2)


# add collections
patches = []
art = mpatches.Circle((0.5,0.5), 0.1,ec="none")
patches.append(art)
art2 = mpatches.Rectangle((0.5,0.5), 0.5, 0.2, fc='r', ec='none')
patches.append(art2)
art3 = mpatches.Arrow(0,0,0.3,0.3,width=0.2)
patches.append(art3)
collection = PatchCollection(patches, cmap=matplotlib.cm.jet, alpha=0.4) # notice the cmap ???
# collection.set_array(np.array(colors))
ax.add_collection(collection)


# ax.axis('equal')
# ax.set_xlim(xxx)
# ax.set_ylim(xxx)
ax.grid(True)
ax.set_title("title here")
show()








# x = arange(0,1,0.01)
# plot(x,sin(2*pi*x))


# # # create 3x3 grid to plot the artists
# # # pos = np.mgrid[0.2:0.8:3j, 0.2:0.8:3j].reshape(2, -1)

# patches = []

# # add a circle
# # art = mpatches.Circle(pos[:,0], 0.1,ec="none")
# art = mpatches.Circle((0.5,0.5), 0.1,ec="none")
# patches.append(art)
# # ax.text(0.5, 0.5-0.15, "Circle", ha="center", family=font, size=14)

# art = mpatches.Rectangle((0.5,0.5), 0.5, 0.2, ec='none')
# # art = mpatches.Rectangle((0.5,0.5), 0.5, 0.2, fc='r', ec='none')
# patches.append(art)

# art = mpatches.Arrow(0,0,0.3,0.3,width=0.2)
# patches.append(art)

# # lines (not append to patches, added to ax)
# line = mlines.Line2D([0,0.2],[0.3,0.4], lw=4, color='r', alpha=0.4) # draw a line (0,0.3) - (0.2,0.4)
# lineX = linspace(0,2,5)
# lineY = [0,0,1,0,0]
# line = mlines.Line2D(lineX, lineY, lw=4, c='b', alpha=0.4)

# setp(line, color='g')           # set the properties of 'line'


# # colors = 100*np.random.rand(len(patches))
# collection = PatchCollection(patches, cmap=matplotlib.cm.jet, alpha=0.4)
# # collection.set_array(np.array(colors))
# # ax.add_collection(collection)


# # ax.add_line(line)               # add lines
# xlim(0,2)                       # must set the xlim/ylim manually
# # ax.set_xticks([])
# # ax.set_yticks([])
# ax.set_xticks([-1, -0.5, 0, 0.5, 1], ['$-\pi$', '$-\pi/2$', '$0$', '$+\pi/2$', '$+\pi$'])


# # savefig("tmp.png", dpi=72)
# # show()




# def plot_circle(center, radius):
#     patches = []
#     art = mpatches.Circle(center, radius, ec='none')
#     patches.append(art)
#     collection = PatchCollection(patches, cmap=matplotlib.cm.jet, alpha=0.4)
#     ax.add_collection(collection)
#     # show()

# plot_circle((0.5,0,5), 0.5)
# show()

